<cfcomponent displayname="announcements" output="false">
	<!---
	PROPERTIES
	--->
	<cfset variables.instance = StructNew() />

	<!---
	INITIALIZATION / CONFIGURATION
	--->
	<cffunction name="init" access="public" returntype="trac_fu.model.announcements.announcements" output="false">
		<cfargument name="id" type="string" required="false" default="" />
		<cfargument name="title" type="string" required="false" default="" />
		<cfargument name="body" type="string" required="false" default="" />
		<cfargument name="projectidfk" type="string" required="false" default="" />
		<cfargument name="useridfk" type="string" required="false" default="" />
		<cfargument name="posted" type="string" required="false" default="" />
		
		<!--- run setters --->
		<cfset setid(arguments.id) />
		<cfset settitle(arguments.title) />
		<cfset setbody(arguments.body) />
		<cfset setprojectidfk(arguments.projectidfk) />
		<cfset setuseridfk(arguments.useridfk) />
		<cfset setposted(arguments.posted) />
		
		<cfreturn this />
 	</cffunction>

	<!---
	PUBLIC FUNCTIONS
	--->
	<cffunction name="setMemento" access="public" returntype="trac_fu.model.announcements.announcements" output="false">
		<cfargument name="memento" type="struct" required="yes"/>
		<cfset variables.instance = arguments.memento />
		<cfreturn this />
	</cffunction>
	<cffunction name="getMemento" access="public" returntype="struct" output="false" >
		<cfreturn variables.instance />
	</cffunction>

	<cffunction name="validate" access="public" returntype="array" output="false">
		<cfset var errors = arrayNew(1) />
		<cfset var thisError = structNew() />
		
		<!--- id --->
		<cfif (NOT len(trim(getid())))>
			<cfset thisError.field = "id" />
			<cfset thisError.type = "required" />
			<cfset thisError.message = "id is required" />
			<cfset arrayAppend(errors,duplicate(thisError)) />
		</cfif>
		<cfif (len(trim(getid())) AND NOT IsSimpleValue(trim(getid())))>
			<cfset thisError.field = "id" />
			<cfset thisError.type = "invalidType" />
			<cfset thisError.message = "id is not a string" />
			<cfset arrayAppend(errors,duplicate(thisError)) />
		</cfif>
		<cfif (len(trim(getid())) GT 35)>
			<cfset thisError.field = "id" />
			<cfset thisError.type = "tooLong" />
			<cfset thisError.message = "id is too long" />
			<cfset arrayAppend(errors,duplicate(thisError)) />
		</cfif>
		
		<!--- title --->
		<cfif (NOT len(trim(gettitle())))>
			<cfset thisError.field = "title" />
			<cfset thisError.type = "required" />
			<cfset thisError.message = "title is required" />
			<cfset arrayAppend(errors,duplicate(thisError)) />
		</cfif>
		<cfif (len(trim(gettitle())) AND NOT IsSimpleValue(trim(gettitle())))>
			<cfset thisError.field = "title" />
			<cfset thisError.type = "invalidType" />
			<cfset thisError.message = "title is not a string" />
			<cfset arrayAppend(errors,duplicate(thisError)) />
		</cfif>
		<cfif (len(trim(gettitle())) GT 50)>
			<cfset thisError.field = "title" />
			<cfset thisError.type = "tooLong" />
			<cfset thisError.message = "title is too long" />
			<cfset arrayAppend(errors,duplicate(thisError)) />
		</cfif>
		
		<!--- body --->
		<cfif (NOT len(trim(getbody())))>
			<cfset thisError.field = "body" />
			<cfset thisError.type = "required" />
			<cfset thisError.message = "body is required" />
			<cfset arrayAppend(errors,duplicate(thisError)) />
		</cfif>
		<cfif (len(trim(getbody())) AND NOT IsSimpleValue(trim(getbody())))>
			<cfset thisError.field = "body" />
			<cfset thisError.type = "invalidType" />
			<cfset thisError.message = "body is not a string" />
			<cfset arrayAppend(errors,duplicate(thisError)) />
		</cfif>
		<cfif (len(trim(getbody())) GT 1073741823)>
			<cfset thisError.field = "body" />
			<cfset thisError.type = "tooLong" />
			<cfset thisError.message = "body is too long" />
			<cfset arrayAppend(errors,duplicate(thisError)) />
		</cfif>
		
		<!--- projectidfk --->
		<cfif (NOT len(trim(getprojectidfk())))>
			<cfset thisError.field = "projectidfk" />
			<cfset thisError.type = "required" />
			<cfset thisError.message = "projectidfk is required" />
			<cfset arrayAppend(errors,duplicate(thisError)) />
		</cfif>
		<cfif (len(trim(getprojectidfk())) AND NOT IsSimpleValue(trim(getprojectidfk())))>
			<cfset thisError.field = "projectidfk" />
			<cfset thisError.type = "invalidType" />
			<cfset thisError.message = "projectidfk is not a string" />
			<cfset arrayAppend(errors,duplicate(thisError)) />
		</cfif>
		<cfif (len(trim(getprojectidfk())) GT 35)>
			<cfset thisError.field = "projectidfk" />
			<cfset thisError.type = "tooLong" />
			<cfset thisError.message = "projectidfk is too long" />
			<cfset arrayAppend(errors,duplicate(thisError)) />
		</cfif>
		
		<!--- useridfk --->
		<cfif (NOT len(trim(getuseridfk())))>
			<cfset thisError.field = "useridfk" />
			<cfset thisError.type = "required" />
			<cfset thisError.message = "useridfk is required" />
			<cfset arrayAppend(errors,duplicate(thisError)) />
		</cfif>
		<cfif (len(trim(getuseridfk())) AND NOT IsSimpleValue(trim(getuseridfk())))>
			<cfset thisError.field = "useridfk" />
			<cfset thisError.type = "invalidType" />
			<cfset thisError.message = "useridfk is not a string" />
			<cfset arrayAppend(errors,duplicate(thisError)) />
		</cfif>
		<cfif (len(trim(getuseridfk())) GT 35)>
			<cfset thisError.field = "useridfk" />
			<cfset thisError.type = "tooLong" />
			<cfset thisError.message = "useridfk is too long" />
			<cfset arrayAppend(errors,duplicate(thisError)) />
		</cfif>
		
		<!--- posted --->
		<cfif (NOT len(trim(getposted())))>
			<cfset thisError.field = "posted" />
			<cfset thisError.type = "required" />
			<cfset thisError.message = "posted is required" />
			<cfset arrayAppend(errors,duplicate(thisError)) />
		</cfif>
		<cfif (len(trim(getposted())) AND NOT isDate(trim(getposted())))>
			<cfset thisError.field = "posted" />
			<cfset thisError.type = "invalidType" />
			<cfset thisError.message = "posted is not a date" />
			<cfset arrayAppend(errors,duplicate(thisError)) />
		</cfif>
		
		<cfreturn errors />
	</cffunction>

	<!---
	ACCESSORS
	--->
	<cffunction name="setid" access="public" returntype="void" output="false">
		<cfargument name="id" type="string" required="true" />
		<cfset variables.instance.id = arguments.id />
	</cffunction>
	<cffunction name="getid" access="public" returntype="string" output="false">
		<cfreturn variables.instance.id />
	</cffunction>

	<cffunction name="settitle" access="public" returntype="void" output="false">
		<cfargument name="title" type="string" required="true" />
		<cfset variables.instance.title = arguments.title />
	</cffunction>
	<cffunction name="gettitle" access="public" returntype="string" output="false">
		<cfreturn variables.instance.title />
	</cffunction>

	<cffunction name="setbody" access="public" returntype="void" output="false">
		<cfargument name="body" type="string" required="true" />
		<cfset variables.instance.body = arguments.body />
	</cffunction>
	<cffunction name="getbody" access="public" returntype="string" output="false">
		<cfreturn variables.instance.body />
	</cffunction>

	<cffunction name="setprojectidfk" access="public" returntype="void" output="false">
		<cfargument name="projectidfk" type="string" required="true" />
		<cfset variables.instance.projectidfk = arguments.projectidfk />
	</cffunction>
	<cffunction name="getprojectidfk" access="public" returntype="string" output="false">
		<cfreturn variables.instance.projectidfk />
	</cffunction>

	<cffunction name="setuseridfk" access="public" returntype="void" output="false">
		<cfargument name="useridfk" type="string" required="true" />
		<cfset variables.instance.useridfk = arguments.useridfk />
	</cffunction>
	<cffunction name="getuseridfk" access="public" returntype="string" output="false">
		<cfreturn variables.instance.useridfk />
	</cffunction>

	<cffunction name="setposted" access="public" returntype="void" output="false">
		<cfargument name="posted" type="string" required="true" />
		<cfset variables.instance.posted = arguments.posted />
	</cffunction>
	<cffunction name="getposted" access="public" returntype="string" output="false">
		<cfreturn variables.instance.posted />
	</cffunction>


	<!---
	DUMP
	--->
	<cffunction name="dump" access="public" output="true" return="void">
		<cfargument name="abort" type="boolean" default="false" />
		<cfdump var="#variables.instance#" />
		<cfif arguments.abort>
			<cfabort />
		</cfif>
	</cffunction>

</cfcomponent>